# 预测隐形眼镜的类型
import trees
import treePlotter
from numpy import *
fr = open('lenses.txt')                     # 打开文件
txt = [inst.strip().split('/t') for inst in fr.readlines()]
numberOfLines = len(txt)         # 获取文件行数
lenses = [[0 for col in range(5)] for row in range(numberOfLines)]  # 初始化lenses
classLabelVector = [0 for row in range(numberOfLines)]              # 初始化classLabelVector标签向量
# 将读取的文本信息转化为元素列表
for index in range (0,numberOfLines):
    t1 = txt[index];
    t2 = t1[0];
    t3 = t2.split('\t');                # 用tab字符\t把整行数据分割成一个元素列表
    lenses[index] = t3;                 # 构造数据集
    classLabelVector[index] = t3[4];    # 取最后一列元素放到classLabelVector标签向量中
    
# 输入特征名
lensesLabels = ['age','prescript','astigmatic','tearRate']
# 生成决策树-----数据集lenses，特征名lensesLabels
lensesTree = trees.createTree(lenses,lensesLabels)
treePlotter.createPlot(lensesTree)
